﻿using RegressionAnalysis.Function;
namespace RegressionAnalysis
{
    class program
    {
        static void Main(string[] args)
        {           
            //利用y=a*e^(bx)对GDP进行分析
            double Basenumer =2.915;
            //用数组记录每年GDP
            double[] GDP = new double[] { 0.059716, 0.050057, 0.047209, 0.050707, 0.059708, 0.070436, 0.07672, 0.072882, 0.070847, 0.079706, 0.092603, 0.099801, 0.113688, 0.138544, 0.144182, 0.163432, 0.15394, 0.174938, 0.149541, 0.178281, 0.191149, 0.195866, 0.20509, 0.230687, 0.259947, 0.309488, 0.300758, 0.272973, 0.312354, 0.347768, 0.360858, 0.383373, 0.426916, 0.444731, 0.564325, 0.734548, 0.863747, 0.961604, 1.03, 1.09, 1.21, 1.34, 1.47, 1.66, 1.96, 2.29, 2.75, 3.55, 4.59, 5.1, 6.09, 7.55, 8.53, 9.57, 10.48, 11.06, 11.23, 12.31, 13.89, 14.28, 14.69, 17.73, };
            int years = GDP.Length;
            //设置参数 其中Y=lny,A=lna;
            double a, b;
            //Y与x的平均值
            double TheAverageOfx, TheAverageOfY;
            //计算x的平均值
            TheAverageOfx = function.Avarage1(years);
            //计算Y的平均值
            TheAverageOfY = function.Avarage2(GDP, Basenumer);
            //计算b的大小
            b = function.ValueOfb(TheAverageOfx, TheAverageOfY, GDP, Basenumer);
            //计算a的大小
            a = Math.Pow(Math.E,TheAverageOfY - b * TheAverageOfx);
            //对某年进行估计
            Console.WriteLine("输入一个年份");
            double year =Convert.ToDouble( Console.ReadLine())-1959;
            double EstimatedValue =a*Math.Pow(Basenumer, year*b);
            Console.WriteLine($"当年预估GDP总量为{EstimatedValue}万亿");
            Console.WriteLine($"偏差为{Math.Abs((EstimatedValue - GDP[(int)year-1]) / GDP[(int)year-1])*100}%");


         }
       
    }
    
}